package com.ruoyi.camp.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.camp.domain.CDetails;
import com.ruoyi.camp.service.ICDetailsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 详情Controller
 * 
 * @author ruoyi
 * @date 2024-11-26
 */
@RestController
@RequestMapping("/camp/details")
public class CDetailsController extends BaseController
{
    @Autowired
    private ICDetailsService cDetailsService;

    /**
     * 查询详情列表
     */
    @PreAuthorize("@ss.hasPermi('camp:details:list')")
    @GetMapping("/list")
    public TableDataInfo list(CDetails cDetails)
    {
        startPage();
        List<CDetails> list = cDetailsService.selectCDetailsList(cDetails);
        return getDataTable(list);
    }

    /**
     * 导出详情列表
     */
    @PreAuthorize("@ss.hasPermi('camp:details:export')")
    @Log(title = "详情", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CDetails cDetails)
    {
        List<CDetails> list = cDetailsService.selectCDetailsList(cDetails);
        ExcelUtil<CDetails> util = new ExcelUtil<CDetails>(CDetails.class);
        util.exportExcel(response, list, "详情数据");
    }

    /**
     * 获取详情详细信息
     */
    @PreAuthorize("@ss.hasPermi('camp:details:query')")
    @GetMapping(value = "/{detailid}")
    public AjaxResult getInfo(@PathVariable("detailid") String detailid)
    {
        return success(cDetailsService.selectCDetailsByDetailid(detailid));
    }

    /**
     * 新增详情
     */
    @PreAuthorize("@ss.hasPermi('camp:details:add')")
    @Log(title = "详情", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CDetails cDetails)
    {
        return toAjax(cDetailsService.insertCDetails(cDetails));
    }

    /**
     * 修改详情
     */
    @PreAuthorize("@ss.hasPermi('camp:details:edit')")
    @Log(title = "详情", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CDetails cDetails)
    {
        return toAjax(cDetailsService.updateCDetails(cDetails));
    }

    /**
     * 删除详情
     */
    @PreAuthorize("@ss.hasPermi('camp:details:remove')")
    @Log(title = "详情", businessType = BusinessType.DELETE)
	@DeleteMapping("/{detailids}")
    public AjaxResult remove(@PathVariable String[] detailids)
    {
        return toAjax(cDetailsService.deleteCDetailsByDetailids(detailids));
    }
}
